import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
def main(database: str,sql: str,host: str,port: str,username: str,password: str) -> dict:
    host = '192.168.16.56'
    port = 30306
    database = 'donge'
    username = 'root'
    password = 'sinoai123456'
    sql = '''
\nWITH annual_sales AS (\n  SELECT `year`, `sales`\n  FROM `dongea_annual_sales`\n  ORDER BY `year` ASC\n),\ntop5_brands AS (\n  SELECT `brand`, `sales`\n  FROM `dongea_top5_brands_2023`\n  ORDER BY `sales` DESC\n  LIMIT 5\n)\nSELECT * FROM annual_sales, top5_brands;\n
    '''

    import pymysql
    import pandas as pd
    # 数据库连接信息
    # host = 'tenant-2102622389-cn-guangzhou-public.bytehouse.volces.com'
    # port = 3306
    # username = 'bytehouse'
    # password = 'gd3gjGTXTb:WBSEjA67dI'
    # 创建数据库连接
    connection = pymysql.connect(
        host=host,
        port=port,
        user=username,
        password=password,
        database=database,
        charset='utf8mb4'
    )
    cursor = connection.cursor()
    cursor.execute(sql)
    columns = [column[0] for column in cursor.description]
    rows = cursor.fetchall()
    df = pd.DataFrame(list(rows), columns=columns)
    # 关闭游标和连接
    cursor.close()
    connection.close()
    print("\n连接已关闭。")
    df_str = df.astype(str)
    df_dict = df_str.to_dict('list')
    return {
        "result": df_dict
    }
